﻿using Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.EntityConfigs
{
    public class UserConfig : BaseEntityConfig<User>
    {
        public override void Configure(EntityTypeBuilder<User> builder)
        {
            base.Configure(builder);

            builder.Property(u => u.LoginName).HasMaxLength(32);
            builder.Property(u => u.RealName).HasMaxLength(50);
            builder.Property(u => u.Password).HasMaxLength(32);
            builder.Property(u => u.Phone).HasMaxLength(50);
            builder.Property(u => u.Email).HasMaxLength(50);
            builder.Property(u => u.ExtInfo).HasConversion(x => ToStr(x, null), x => ToObj<ExtInfo>(x, null)).HasColumnType("text").IsUnicode(false);

            builder.HasData(_users);
        }

        private readonly List<User> _users =
        [
            new() {
                Id=111,
                Status = UserStatus.Enable,Attr= UserAttr.TypeUser|UserAttr.TypeMangerUser,
                CreateTime=DateTime.Now,Phone="17796703670",LoginName="Yzy",Email="11727146@qq.com",
                ExtInfo=new ExtInfo{Roles=[132]},Password="123",RealName="Yzy",UpdateTime=DateTime.Now
            },
             new() {
                Id=222,
                Status = UserStatus.Enable,Attr= UserAttr.TypeUser|UserAttr.TypeMangerUser,
                CreateTime=DateTime.Now,Phone="17796703670",LoginName="Yzy",Email="11727146@qq.com",
                ExtInfo=new ExtInfo{Roles=[132]},Password="123",RealName="Yzy",UpdateTime=DateTime.Now
            },
              new() {
                Id=333,
                Status = UserStatus.Enable,Attr= UserAttr.TypeUser|UserAttr.TypeMangerUser,
                CreateTime=DateTime.Now,Phone="17796703670",LoginName="Yzy",Email="11727146@qq.com",
                ExtInfo=new ExtInfo{Roles=[132]},Password="123",RealName="Yzy",UpdateTime=DateTime.Now
            }
        ];
    }
}
